module ControlHazard(
    input [31:0] PC,
    input [31:0] nextPC_in,
    input exception,
    input isbranch,
    input [31:0] EX_Inst,

    output [31:0] nextPC_out,
    output reg IF_flush,
    output reg ID_flush,
    output reg EX_flush,
    output reg [1:0] PCSrc
);

    assign nextPC_out = nextPC_in;

    always @(*) begin
        if(exception) begin
            PCSrc = 2;
            IF_flush = 1;
            ID_flush = 1;
            EX_flush = 1;
        end
        else if(EX_Inst == 32'h42000018) begin
            IF_flush = 1; // eret no delay slot 
            ID_flush = 0; // the Inst must be nop
            EX_flush = 0;
            PCSrc = 1;
        end
        else if(isbranch) begin
            // IF_flush = 1;
            IF_flush = 0; // delay slot
            ID_flush = 0;
            EX_flush = 0;
            PCSrc = 1;
        end
        else begin
            IF_flush = 0;
            ID_flush = 0;
            EX_flush = 0;
            PCSrc = 0;
        end
    end
endmodule // ControlHazard